getValueByParam = (name) => {
	return new URLSearchParams(window.location.search).get(name);
}

ArrayEmpty = (arr) => {
	if (Array.isArray(arr)) {
		if (arr.length > 0) {
			return false
		} else {
			return true
		}
	}
	return true
}

toObjectStr = (e) => {
	return JSON.stringify(e).replace(/"/g, '&quot;');
}

toObject = (e) => {
	return JSON.parse(e);
}

setKeepAliveIndex = (index) => {
	window.localStorage.setItem('tabbarIndex', index);
}

getKeepAliveIndex = () => {
	return window.localStorage.getItem('tabbarIndex')
}

/**
 *  防抖函数
 *  @param fn：需要防抖的函数（也就是被频繁触发的函数）
 *  @param delay：毫秒数（设定的时间间隔）
 */
debounce = (fn, delay) => {
	let timeout = null;
	return function(...arguments) {
		let context = this;
		let args = arguments;
		if (timeout) clearTimeout(timeout);
		let callNow = !timeout;
		timeout = setTimeout(() => {
			timeout = null;
		}, delay);
		if (callNow) {
			fn.apply(context, args)
		} else {
			showToast('别点太快啦！')
		};
	};
}

/**
 *  节流函数
 *  @param fn：需要节流的函数（被连续触发的函数）
 *  @param delay：毫秒数（设定的时间）
 */
throttle = (fn, delay = 500) => {
	let lastTime = 0;
	return function(...args) {
		const now = Date.now();
		if (now - lastTime >= delay) {
			fn.apply(this, args);
			lastTime = now;
		}
	}
}

isValidPhoneNumber = (phoneNumber) => {
	const regExp = /^1[0-9]{10}$/; // 以1开头，后面跟10位数字
	return regExp.test(phoneNumber);
}

/**
 * 将手机号码中间四位替换为星号(*)
 */
maskPhoneNumber = (phoneNumber) => {
	return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}

/**
 * 页面跳转相关
 */
navigateTo = (url) => {
	window.location.href = url
}

isEmpty = (param) => {
	if (null == param || "null" == param || param.length == 0 || 'undefined' == param) {
		return true;
	}
	return false;
}

/**
 * html转义显示, 防止XSS攻击
 * @param {string} value 
 * @returns 
 */
htmlEncode = (value) => {
	return $('<div/>').text(value).html();
}

onCallphone = (phone) => {
	event.stopImmediatePropagation(); //阻止事件分发
	if (!isEmpty(phone)) {
		window.location.href = "tel:" + phone;
	}
}

replacePage = (url) => {
	window.location.replace(url)
}

goBack = () => setTimeout(() => {
	window.history.go(-1);
}, 500)

setPageTitle = (text) => {
	document.title = text
}

setStorageValue = (key, value) => {
	window.localStorage.setItem(key, value)
}

getStorageValue = (key) => {
	return window.localStorage.getItem(key)
}

storageClear = () => {
	window.localStorage.clear();
	window.location.reload();
}

/**
 * html转义显示, 防止XSS攻击
 * @param {string} value 
 * @returns 
 */
htmlEncode = (value) => {
	return $('<div/>').text(value).html();
}

onCallphone = (phone) => {
	event.stopImmediatePropagation(); //阻止事件分发
	if (!isEmpty(phone)) {
		window.location.href = "tel:" + phone;
	}
}

showToast = (msg) => {
	layer.open({
		type: 1,
		content: msg,
		skin: 'msg',
		time: 2 //2秒后自动关闭
	});
}

showActionDialog = (title, msg, callback) => {
	layer.open({
		title: [
			title ? title : '温馨提示',
			'background-color:white; color:#FF34B3;'
		],
		anim: 'up',
		shadeClose: false,
		content: msg,
		btn: ['确定', '取消'],
		yes: function(index) {
			layer.close(index);
			callback(index);
		}
	});
}

showTipsDialog = (msg) => {
	layer.open({
		title: [
			'温馨提示',
			'background-color:white; color:#FF34B3;'
		],
		anim: 'up',
		shadeClose: false,
		content: msg,
		btn: '我知道了'
	});
}

noData = () => '暂无数据';

requestTimeOut = () => '请求超时，请检查';

getStartText = () => '正在加载...';

loginFail = () => '请求失败!';

startLoading = () => {
	$("#state_img").hide();
	$("#load_layout").show();
	$("#loading").show();
	$("#state_text").show();
	$("#state_text").text(getStartText());
}

hideLoading = () => {
	$("#load_layout").hide();
}

setLoadState = (stateUlr, stateMsg) => {
	$("#load_layout").show();
	$("#loading").hide();
	$("#state_img").show();
	$("#state_text").text(stateMsg);
}

startLoading2 = () => {
	$("#state_img_1").hide();
	$("#load_layout_1").show();
	$("#loading_1").show();
	$("#state_text_1").show();
	$("#state_text_1").text(getStartText());
}

hideLoading2 = () => {
	$("#load_layout_1").hide();
}

setLoadState2 = (stateUlr, stateMsg) => {
	$("#load_layout_1").show();
	$("#loading_1").hide();
	$("#state_img_1").show();
	$("#state_text_1").text(stateMsg);
}

startLoading3 = () => {
	$("#state_img_2").hide();
	$("#load_layout_2").show();
	$("#loading_2").show();
	$("#state_text_2").show();
	$("#state_text_2").text(getStartText());
}

hideLoading3 = () => {
	$("#load_layout_2").hide();
}

setLoadState3 = (stateUlr, stateMsg) => {
	$("#load_layout_2").show();
	$("#loading_2").hide();
	$("#state_img_2").show();
	$("#state_text_2").text(stateMsg);
}

setLoadingState = (layoutId, loadingId, iconId, textId, index) => { //index :0是开始 1是暂无数据  2是请求失败,-1是隐藏
	if (index == 0) {
		$(`#${layoutId}`).show();
		$(`#${loadingId}`).show();
		$(`#${textId}`).show();
		$(`#${textId}`).text(getStartText());
		$(`#${iconId}`).hide();
	} else if (index == 1) {
		$(`#${layoutId}`).show();
		$(`#${iconId}`).show();
		$(`#${loadingId}`).hide();
		$(`#${textId}`).text(noData());
	} else if (index == 2) {
		$(`#${layoutId}`).show();
		$(`#${iconId}`).show();
		$(`#${loadingId}`).hide();
		$(`#${textId}`).text(loginFail());
	} else {
		$(`#${layoutId}`).hide();
	}
}
